//
//  JKOCRealmSaveModelTests.m
//  JKOCRealmTests
//
//  Created by 王冲 on 2019/2/26.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.
//

#import <XCTest/XCTest.h>
#import <Realm/Realm.h>
#import "Student.h"
#import "Dog.h"
@interface JKOCRealmSaveModelTests : XCTestCase

@end

@implementation JKOCRealmSaveModelTests

#pragma mark 保存model模型
- (void)testRealmSaveModel{
    
    
    Student *student = [[Student alloc]initWithValue:@{@"studentId":@6,@"studentName":@"刘二"}];
    
    NSLog(@"目录=%@",NSHomeDirectory());
    
    RLMRealm *realm = [RLMRealm defaultRealm];
    
    // 方式一：开启事务，写入数据，关闭事务
    /*
     // 开启事务
     [realm beginWriteTransaction];
     // 写入数据
     [realm addObject:student];
     // 关闭事务
     [realm commitWriteTransaction];
     */
    
    // 方式二：使用 block
    
    [realm transactionWithBlock:^{
        
        [realm addObject:student];
        // [Student createInRealm:realm withValue:@{@"studentId": @3, @"studentName": @"马冬梅2"}];
    }];
    
}
    

#pragma mark 保存model模型
- (void)testRealmSaveModel2{
    
    
    Dog *dog = [[Dog alloc]initWithValue:@{@"dogId":@1,@"dogName":@"旺财"}];
    RLMRealm *realm = [RLMRealm defaultRealm];
    
    NSLog(@"目录=%@",NSHomeDirectory());

    [realm transactionWithBlock:^{
        
        [realm addObject:dog];
       
    }];
    
}

@end
